package main

import (
	"fmt"
	"time"
)

func plusOne(digits []int) []int {
	len := len(digits)

	digits[len-1] += 1
	for i := len - 1; i >= 0; i-- {
		if digits[i] < 9 {
			break
		}
		if digits[i] > 9 {
			digits[i] = 0
			if i-1 >= 0 {
				digits[i-1] += 1
			}
			if i-1 < 0 {
				single := []int{1}
				digits = append(single[:], digits...)

			}

		}

	}
	return digits

}

func main() {
	start := time.Now()
	digits := []int{8, 9, 9, 9}
	des := plusOne(digits)
	cost := time.Since(start)
	fmt.Println(des)
	fmt.Println(cost)

}
